#include <iostream>
#include <memory>
#include <string>

//抽象的水果类
class Fruit
{
public:
    Fruit()
    {}
    virtual void show() = 0;
};

//水果类派生出的具体类
class Apple : public Fruit
{
public:
    Apple(){}
    void show() override
    {
        std::cout << "我是一个苹果!" << std::endl;
    }
};

class Banana : public Fruit
{
public: 
    Banana(){}
    void show() override
    {
        std::cout << "我是一个香蕉!" << std::endl;
    }
};



class FruitFactory 
{
public:
    FruitFactory() {};
    std::shared_ptr<Fruit> create(const std::string &name) 
    {
        if( name == "苹果")
        {
            return std::make_shared<Apple>();
        }
        else if(name == "香蕉")
        {
            return std::make_shared<Banana>();
        }
  
        return std::shared_ptr<Fruit>();
    }
};


int main()
{
    // std::shared_ptr<FruitFactory> ff = std::make_shared<FruitFactory>();
    std::shared_ptr<FruitFactory> ff;
    ff = std::make_shared<FruitFactory>();

    std::shared_ptr<Fruit> fr = ff->create("苹果");
    fr->show();
    fr = ff->create("香蕉");
    fr->show();
    return 0;
}